/*
 * oosvafs_HAL.c

 *
 *  Created on: 29/03/2014
 *      Author: Michelangelo
 */
#include "Comum.h"

extern Error_States errorCode;


/*******************************************************************************
* @NAME:               HAL_config_timer                        	               *
* @BRIEF:              Configures the timer for pwm			                   *
* @CREATED_BY:         Ricardo Sa                                              *
* @CREATION_DATE:      29 mar 2014                                             *
* @PARAM:			   PWM Timer number (0-4); periodo(Hz)                     *
* @LIB_REF:                                                                    *
* @LIB_REUSE_%:                                                                *
********************************************************************************/
void HAL_config_timer(INT8U timer, INT16U refresh_rate)
{
	/*  Portado para BRTOS  */
	// set refresh rate
	uint32_t period1 = SysCtlClockGet() / refresh_rate; /*Hz*/
	uint8_t extender1 = period1 >> 16;
	period1 &= 0xFFFF;

	/*  Portado para BRTOS  */
	//set default
	uint32_t period2 = tics_us*default_pulse;
	uint8_t extender2 = period2 >> 16;
	period2 &= 0xFFFF;

	if(refresh_rate == 0)
	{
		errorCode = Err_1;
	}
	else
	{

		switch (timer){

		case 0: {
			/*  Portado para BRTOS  */
			// Configure output, PB6/7 as T0CCP0/1
			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
			GPIOPinConfigure(GPIO_PB6_T0CCP0);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
			GPIOPinConfigure(GPIO_PB7_T0CCP1);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7);
			// Configure timer
			SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
			TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
			HWREG(TIMER0_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML|TIMER_CTL_TBPWML);
			//set period
			TimerPrescaleSet(TIMER0_BASE, TIMER_A, extender1);
			TimerLoadSet(TIMER0_BASE, TIMER_A, period1);
			TimerPrescaleSet(TIMER0_BASE, TIMER_B, extender1);
			TimerLoadSet(TIMER0_BASE, TIMER_B, period1);
			//set default value A
			TimerPrescaleMatchSet(TIMER0_BASE, TIMER_A, extender2);
			TimerMatchSet(TIMER0_BASE, TIMER_A, period2);
			//set default value B
			TimerPrescaleMatchSet(TIMER0_BASE, TIMER_B, extender2);
			TimerMatchSet(TIMER0_BASE, TIMER_B, period2);
			TimerEnable(TIMER0_BASE, TIMER_A|TIMER_B);
			break;}

		case 1: {// Configure output, PB4/5 as T1CCP0/1
			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
			GPIOPinConfigure(GPIO_PB4_T1CCP0);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4);
			GPIOPinConfigure(GPIO_PB5_T1CCP1);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);
			// Configure timer
			SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
			TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
			HWREG(TIMER1_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML|TIMER_CTL_TBPWML);
			//set period
			TimerPrescaleSet(TIMER1_BASE, TIMER_A, extender1);
			TimerLoadSet(TIMER1_BASE, TIMER_A, period1);
			TimerPrescaleSet(TIMER1_BASE, TIMER_B, extender1);
			TimerLoadSet(TIMER1_BASE, TIMER_B, period1);
			//set default value A
			TimerPrescaleMatchSet(TIMER1_BASE, TIMER_A, extender2);
			TimerMatchSet(TIMER1_BASE, TIMER_A, period2);
			//set default value B
			TimerPrescaleMatchSet(TIMER1_BASE, TIMER_B, extender2);
			TimerMatchSet(TIMER1_BASE, TIMER_B, period2);
			TimerEnable(TIMER1_BASE, TIMER_A|TIMER_B);
			break;}

		case 2: {// Configure output, PB0/1 as T2CCP0/1
			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
			GPIOPinConfigure(GPIO_PB0_T2CCP0);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0);
			GPIOPinConfigure(GPIO_PB1_T2CCP1);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1);
			// Configure timer
			SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
			TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
			HWREG(TIMER2_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML|TIMER_CTL_TBPWML);
			//set period
			TimerPrescaleSet(TIMER2_BASE, TIMER_A, extender1);
			TimerLoadSet(TIMER2_BASE, TIMER_A, period1);
			TimerPrescaleSet(TIMER2_BASE, TIMER_B, extender1);
			TimerLoadSet(TIMER2_BASE, TIMER_B, period1);
			//set default value A
			TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, extender2);
			TimerMatchSet(TIMER2_BASE, TIMER_A, period2);
			//set default value B
			TimerPrescaleMatchSet(TIMER2_BASE, TIMER_B, extender2);
			TimerMatchSet(TIMER2_BASE, TIMER_B, period2);
			TimerEnable(TIMER2_BASE, TIMER_A|TIMER_B);
			break;}

		case 3: {// Configure output, PB2/3 as T3CCP0/1
			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
			GPIOPinConfigure(GPIO_PB2_T3CCP0);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);
			GPIOPinConfigure(GPIO_PB3_T3CCP1);
			GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_3);
			// Configure timer
			SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
			TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
			HWREG(TIMER3_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML|TIMER_CTL_TBPWML);
			//set period
			TimerPrescaleSet(TIMER3_BASE, TIMER_A, extender1);
			TimerLoadSet(TIMER3_BASE, TIMER_A, period1);
			TimerPrescaleSet(TIMER3_BASE, TIMER_B, extender1);
			TimerLoadSet(TIMER3_BASE, TIMER_B, period1);
			//set default value A
			TimerPrescaleMatchSet(TIMER3_BASE, TIMER_A, extender2);
			TimerMatchSet(TIMER3_BASE, TIMER_A, period2);
			//set default value B
			TimerPrescaleMatchSet(TIMER3_BASE, TIMER_B, extender2);
			TimerMatchSet(TIMER3_BASE, TIMER_B, period2);
			TimerEnable(TIMER3_BASE, TIMER_A|TIMER_B);
			break;}

		case 4: {// Configure output, PB2/3 as T3CCP0/1
					SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
					GPIOPinConfigure(GPIO_PC4_WT0CCP0);
					GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_4);
					GPIOPinConfigure(GPIO_PC5_WT0CCP1);
					GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_5);
					// Configure timer
					SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);
					TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
					HWREG(WTIMER0_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML|TIMER_CTL_TBPWML);
					//set period
					TimerPrescaleSet(WTIMER0_BASE, TIMER_A, extender1);
					TimerLoadSet(WTIMER0_BASE, TIMER_A, period1);
					TimerPrescaleSet(WTIMER0_BASE, TIMER_B, extender1);
					TimerLoadSet(WTIMER0_BASE, TIMER_B, period1);
					//set default value A
					TimerPrescaleMatchSet(WTIMER0_BASE, TIMER_A, extender2);
					TimerMatchSet(WTIMER0_BASE, TIMER_A, period2);
					//set default value B
					TimerPrescaleMatchSet(WTIMER0_BASE, TIMER_B, extender2);
					TimerMatchSet(WTIMER0_BASE, TIMER_B, period2);
					TimerEnable(WTIMER0_BASE, TIMER_A|TIMER_B);
					break;}

		default: {
			errorCode = Err_1;
			break;}
		}
	}
}
/*******************************************************************************
 * @NAME:               HAL_set_pwm			                                    *
 * @BRIEF:              sets 24-bit pwm values to timer0A-timer3B				*
 * 						registers -> channels 0-7                               *
 * @CREATED_BY:         Ricardo Sa                                              *
 * @CREATION_DATE:      29 mar 2014                                             *
 * @PARAM:				Canal (A ou B); duty cicle                              *
 * @LIB_REF:                                                                    *
 * @LIB_REUSE_%:                                                                *
 ********************************************************************************/
void HAL_set_pwm (INT8U chan, INT16U pulse)
{
	if(pulse > 25000)
	{
		errorCode = Err_2;
	}
	else{

		//calc and set pwm timer value, no deadtime interlock!
		/*  Portado para BRTOS  */
		uint32_t pwm_period = tics_us*pulse;
		uint8_t pwm_extender = pwm_period >> 16;
		pwm_period &= 0xFFFF;




		switch (chan) {

		case 0: {
			/*  Portado para BRTOS  */
			TimerPrescaleMatchSet(TIMER0_BASE, TIMER_A, pwm_extender);
			TimerMatchSet(TIMER0_BASE, TIMER_A, pwm_period);
			break;   }
		case 1: {
			/*  Portado para BRTOS  */
			TimerPrescaleMatchSet(TIMER0_BASE, TIMER_B, pwm_extender);
			TimerMatchSet(TIMER0_BASE, TIMER_B, pwm_period);
			break;   }
		case 2: {
			TimerPrescaleMatchSet(TIMER1_BASE, TIMER_A, pwm_extender);
			TimerMatchSet(TIMER1_BASE, TIMER_A, pwm_period);
			break;   }
		case 3: {
			TimerPrescaleMatchSet(TIMER1_BASE, TIMER_B, pwm_extender);
			TimerMatchSet(TIMER1_BASE, TIMER_B, pwm_period);
			break;   }
		case 4: {
			TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, pwm_extender);
			TimerMatchSet(TIMER2_BASE, TIMER_A, pwm_period);
			break;   }
		case 5: {
			TimerPrescaleMatchSet(TIMER2_BASE, TIMER_B, pwm_extender);
			TimerMatchSet(TIMER2_BASE, TIMER_B, pwm_period);
			break;   }
		case 6: {
			TimerPrescaleMatchSet(TIMER3_BASE, TIMER_A, pwm_extender);
			TimerMatchSet(TIMER3_BASE, TIMER_A, pwm_period);
			break;   }
		case 7: {
			TimerPrescaleMatchSet(TIMER3_BASE, TIMER_B, pwm_extender);
			TimerMatchSet(TIMER3_BASE, TIMER_B, pwm_period);
			break;   }
		case 8: {
					TimerPrescaleMatchSet(WTIMER0_BASE, TIMER_B, pwm_extender);
					TimerMatchSet(WTIMER0_BASE, TIMER_B, pwm_period);
					break;   }
		default: {
			errorCode = Err_2;
			break; }
		}
	}
}
/********************************************************************************
 * @NAME:               HAL_config_ports                                        *
 * @BRIEF:              Configure the ports and pins as input or output			*
 * @CREATED_BY:         Ricardo Sa                                              *
 * @CREATION_DATE:      29 mar 2014 											*
 * @param				porta (A - F), pin (0-7) type (HAL_INPUT or HAL_OUTPUT) *
 * @SPEC_REF:                                                                   *
 * @LIB_REF:                                                                    *
 * @LIB_REUSE_%:                                                                *
 ********************************************************************************/
void HAL_config_ports(INT8U porta, INT16U pin, INT8U type)
{

	INT32U port;

	if(type > 2)
	{
		errorCode = Err_3;
	}
	else
	{

		switch (porta){

		case 'A': {
			/*  Portado para BRTOS  */

			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
			port = GPIO_PORTA_BASE;

			break;}

		case 'B': {
			/*  Portado para BRTOS  */

			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
			port = GPIO_PORTB_BASE;

			break;}

		case 'C': {
			/*  Portado para BRTOS  */

			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
			port = GPIO_PORTC_BASE;
			break;}

		case 'D': {
			/*  Portado para BRTOS  */

			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
			port = GPIO_PORTD_BASE;
			break;}
		case 'E': {
			/*  Portado para BRTOS  */

			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
			port = GPIO_PORTE_BASE;
			break;}
		case 'F': {
			/*  Portado para BRTOS  */

			SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
			port = GPIO_PORTF_BASE;
			break;}
		default: {
			errorCode = Err_3;
			break;}
		}

		switch (pin){

		case 0: {
			/*  Portado para BRTOS  */
			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_0);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_0);
			}
			break;}

		case 1: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_1);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_1);
			}

			break;}

		case 2: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_2);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_2);
			}

			break;}

		case 3: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_3);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_3);
			}

			break;}
		case 4: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_4);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_4);
			}

			break;}
		case 5: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_5);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_5);
			}

			break;}
		case 6: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_6);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_6);
			}

			break;}
		case 7: {
			/*  Portado para BRTOS  */

			if(type == HAL_INPUT)
			{
				GPIOPinTypeGPIOInput (port, GPIO_PIN_7);
			}
			else if(type == HAL_OUTPUT)
			{
				GPIOPinTypeGPIOOutput (port, GPIO_PIN_7);
			}

			break;}
		default: {
			errorCode = Err_3;
			break;}
		}
	}
}

/********************************************************************************
 * @NAME:               HAL_Write_Pins                              	        *
 * @BRIEF:              Writes value in pins 									*
 * @CREATED_BY:         Ricardo Sa                                              *
 * @CREATION_DATE:      29 mar 2014                                             *
 * @PARAM:				Porta( A - F); pino(0 - 7), High or Low                 *
 * @LIB_REF:                                                                    *
 * @LIB_REUSE_%:                                                                *
 ********************************************************************************/
void HAL_Write_Pins(INT8U porta, INT16U pin, INT8U value)
{

	INT32U port;

//	HAL_config_ports(porta , pin, HAL_OUTPUT); //Right

	if(value > 1)
	{

		errorCode = Err_4;
	}
	else{

		switch (porta){

		case 'A': {
			port = GPIO_PORTA_BASE;
			break;}
		case 'B': {
			port = GPIO_PORTB_BASE;
			break;}
		case 'C': {
			port = GPIO_PORTC_BASE;
			break;}
		case 'D': {
			port = GPIO_PORTD_BASE;
			break;}
		case 'E': {
			port = GPIO_PORTE_BASE;
			break;}
		case 'F': {
			port = GPIO_PORTF_BASE;
			break;}
		default: {
			errorCode = Err_4;
			break;}
		}

		switch (pin){

		case 0: {
			/*  Portado para BRTOS  */
			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_0, GPIO_PIN_0);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_0, 0);
			}
			break;}

		case 1: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_1, GPIO_PIN_1);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_1, 0);
			}

			break;}

		case 2: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_2, GPIO_PIN_2);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_2, 0);
			}
			break;}

		case 3: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_3, GPIO_PIN_3);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_3, 0);
			}

			break;}
		case 4: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_4, GPIO_PIN_4);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_4, 0);
			}

			break;}
		case 5: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_5, GPIO_PIN_5);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_5, 0);
			}

			break;}
		case 6: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_6, GPIO_PIN_6);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_6, 0);
			}

			break;}
		case 7: {
			/*  Portado para BRTOS  */

			if(value == HIGH)
			{
				GPIOPinWrite(port, GPIO_PIN_7, GPIO_PIN_7);
			}
			else if(value == LOW)
			{
				GPIOPinWrite(port, GPIO_PIN_7, 0);
			}

			break;}
		default: {
			errorCode = Err_4;
			break;}

		}
	}
}


/********************************************************************************
 * @NAME:               HAL_Read_Pins                               	        *
 * @BRIEF:              Reads value in pins 									*
 * @CREATED_BY:         Ricardo Sa                                              *
 * @CREATION_DATE:      29 mar 2014                                             *
 * @PARAM:				Porta(A - F); Pino ( 0 - 7)                             *
 * @LIB_REF:                                                                    *
 * @LIB_REUSE_%:                                                                *
 ********************************************************************************/
BOOLEAN HAL_Read_Pins(INT8U porta, INT16U pin)
{

	INT32U port;
	BOOLEAN valor;

	//HAL_config_ports(porta , pin, HAL_OUTPUT); //Right

	switch (porta){

	case 'A': {
		port = GPIO_PORTA_BASE;
		break;}
	case 'B': {
		port = GPIO_PORTB_BASE;
		break;}
	case 'C': {
		port = GPIO_PORTC_BASE;
		break;}
	case 'D': {
		port = GPIO_PORTD_BASE;
		break;}
	case 'E': {
		port = GPIO_PORTE_BASE;
		break;}
	case 'F': {
		port = GPIO_PORTF_BASE;
		break;}
	default: {
		errorCode = Err_5;
		break;}
	}

	switch (pin){

	case 0: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_0))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_0))
		{
			valor = FALSE;
		}

		break;}

	case 1: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_1))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_1))
		{
			valor = FALSE;
		}

		break;}

	case 2: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_2))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_2))
		{
			valor = FALSE;
		}

		break;}

	case 3: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_3))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_3))
		{
			valor = FALSE;
		}

		break;}
	case 4: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_4))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_4))
		{
			valor = FALSE;
		}

		break;
	}
	case 5: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_5))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_5))
		{
			valor = FALSE;
		}

		break;}
	case 6: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_6))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_6))
		{
			valor = FALSE;
		}

		break;}
	case 7: {
		/*  Portado para BRTOS  */

		if(GPIOPinRead(port, GPIO_PIN_7))
		{
			valor = TRUE;
		}
		else if(!GPIOPinRead(port, GPIO_PIN_7))
		{
			valor = FALSE;
		}

		break;}
	default: {
		errorCode = Err_5;
		break;}


	}
	return valor;
}

/********************************************************************************
 * @NAME:               HAL_Config_UART                              	        *
 * @BRIEF:              Writes value in pins 									*
 * @CREATED_BY:         Ricardo Sa                                              *
 * @CREATION_DATE:      29 mar 2014                                             *
 * @SPEC_REF:                                                                   *
 * @LIB_REF:                                                                    *
 * @LIB_REUSE_%:                                                                *
 ********************************************************************************/
void HAL_Config_UART()
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTStdioInit(0);//

}

/********************************************************************************
 * @NAME:               HAL_Config_Count                              	        *
 * @BRIEF:              Writes value in pins 									*
 * @CREATED_BY:         Ricardo Sa                                              *
 * @CREATION_DATE:      29 mar 2014                                             *
 * @SPEC_REF:                                                                   *
 * @LIB_REF:                                                                    *
 * @LIB_REUSE_%:                                                                *
 ********************************************************************************/
void HAL_Config_Count()
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);

	TimerDisable(TIMER3_BASE, TIMER_BOTH);

	GPIOPinConfigure(GPIO_PB2_T3CCP0);  //timer A
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);


	TimerConfigure(TIMER3_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP);

	TimerControlEvent(TIMER3_BASE,TIMER_BOTH,TIMER_EVENT_POS_EDGE);

	//TimerEnable(TIMER3_BASE, TIMER_BOTH);

}





